package cn.edu.scau.cmi.liuan.exp4;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class ClassAdapterClient extends Application {
	Pane p = new Pane();
	Text t1 = new Text();
	Text t2 = new Text();
	Button bt_Class = new Button();
	Button bt_Object = new Button();
	ImageView iv = new ImageView();
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		t1.setText("问题背景：已有一个Adaptee类能够输出220V的电压，\n现在编写Target接口要求实现该接口的类输出5V电压，且只有Adaptee类提供的220V电压\n");
		t1.setFont(Font.font ("Verdana", 20));
		t1.setLayoutX(50);
		t1.setLayoutY(50);
		
		t2.setText("");
		t2.setFont(Font.font ("Verdana", 18));
		t2.setLayoutX(150);
		t2.setLayoutY(200);
		
		bt_Class.setText("类适配器模式");
		bt_Class.setLayoutX(10);
		bt_Class.setLayoutY(200);
		bt_Class.setOnAction(e -> event_Class());
		
		bt_Object.setText("对象适配器模式");
		bt_Object.setLayoutX(10);
		bt_Object.setLayoutY(230);
		bt_Object.setOnAction(e -> event_Object());
		
		iv.setLayoutX(200);
		iv.setLayoutY(300);
		
		p.setPrefSize(900, 500);
		p.getChildren().addAll(t1,bt_Class,bt_Object,t2,iv);
		Scene scene = new Scene(p,900,500);
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	private void event_Object() {
		Adaptee a = new Adaptee();
		ObjectAdapter oa = new ObjectAdapter(a);
		oa.outPut5V();
		
		t2.setText(a.toString() + "\n" + oa.toString());
		
	}

	private void event_Class() {
		ClassAdapter ca = new ClassAdapter();
		ca.outPut5V();
		
		t2.setText(new Adaptee().toString() + "\n" + ca.toString());
		
	}
}
